package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.macro.mall.dao.PmsProductAttributeCategoryDao;
import com.macro.mall.dto.PmsProductAttributeCategoryItem;
import com.macro.mall.mapper.PmsProductAttributeCategoryMapper;
import com.macro.mall.model.PmsProductAttributeCategory;
import com.macro.mall.model.PmsProductAttributeCategoryExample;
import com.macro.mall.service.PmsProductAttributeCategoryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/** 商品属性分类管理Service实现类 Created by macro on 2018/4/26. */
@Service
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
  @Autowired private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
  @Autowired private PmsProductAttributeCategoryDao productAttributeCategoryDao;

  @Override
  public int create(String name) {
    PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
    productAttributeCategory.setName(name);
    return productAttributeCategoryMapper.insertSelective(productAttributeCategory);
  }

  @Override
  public int update(Long id, String name) {
    PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
    productAttributeCategory.setName(name);
    productAttributeCategory.setId(id);
    return productAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
  }

  @Override
  public int delete(Long id) {
    return productAttributeCategoryMapper.deleteByPrimaryKey(id);
  }

  @Override
  public PmsProductAttributeCategory getItem(Long id) {
    return productAttributeCategoryMapper.selectByPrimaryKey(id);
  }

  @Override
  public List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum) {
    PageHelper.startPage(pageNum, pageSize);
    return productAttributeCategoryMapper.selectByExample(new PmsProductAttributeCategoryExample());
  }

  @Override
  public List<PmsProductAttributeCategoryItem> getListWithAttr() {
    return productAttributeCategoryDao.getListWithAttr();
  }
}
